//
//  FindCell.m
//  CBT
//
//  Created by Mr.Zhang on 2019/1/2.
//  Copyright © 2019 Mr.Zhang. All rights reserved.
//

#import "FindCell.h"
#import "FindCollectionViewCell.h"

@interface FindCell()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *iconTitleLabel;

@end

@implementation FindCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = UIColorFromRGB(0xf1f1f1);
    self.collectionView.delegate   = self;
    self.collectionView.dataSource = self;
    self.collectionView.showsVerticalScrollIndicator = YES;
}

- (void)changeLanguage
{
    self.iconTitleLabel.text = kLocalizedString(self.model.sectionText, nil);
}

-(void)setModel:(FindModel *)model
{
    _model = model;
    
    self.iconTitleLabel.text = kLocalizedString(model.sectionText, nil);
    self.iconImageView.image = [UIImage imageNamed:model.sectionIconName];
    
    [self.collectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.model.itemModelArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FindCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FindCollectionCellID" forIndexPath:indexPath];
    cell.itemModel = self.model.itemModelArray[indexPath.row];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((CGRectGetWidth(self.bounds) - 45) / 4, 105);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.FindCellSelectBlock != nil) {
        self.FindCellSelectBlock(((FindCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]).showLabel.text);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
